<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>账号管理-总控后台</title>
		<link rel="shortcut icon" href="favicon.ico">
		<link rel="stylesheet" href="../layui/css/layui.css">
	</head>

	<body>
		<div style="padding: 15px;">
			<!-- 页面内容 Start -->
			<blockquote class="layui-elem-quote layui-text">
				账号编辑
			</blockquote>
			<div class="layui-card layui-panel">
				<div class="layui-card-body">
					<form class="layui-form" action="" style="margin: 20px;">
						<div class="layui-form-item">
							<label class="layui-form-label">账号</label>
							<div class="layui-input-inline layui-input-wrap">
								<input type="text" name="account" lay-verify="required" placeholder="请输入账号"
									autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码</label>
							<div class="layui-input-inline layui-input-wrap">
								<input type="password" name="password" lay-verify="required" autocomplete="off"
									placeholder="请输入密码" lay-affix="clear" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">手机号码</label>
							<div class="layui-input-inline layui-input-wrap">
								<input type="password" name="mobile" lay-verify="required" autocomplete="off"
									placeholder="请输入手机号码" lay-affix="clear" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">角色</label>
							<div class="layui-input-inline layui-input-wrap">
								<select name="role_id" lay-filter="aihao">
									<option value="" selected>请选择</option>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">状态</label>
							<div class="layui-input-block">
								<input type="radio" name="status" value="1" title="正常" checked>
								<input type="radio" name="status" value="2" title="禁用">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>
						</div>
					</form>
				</div>
			</div>
			<!-- 页面内容 End -->
		</div>
		<script src="../layui/layui.js"></script>
		<script type="text/javascript">
			layui.use(['form', 'tree'], function() {
				var form = layui.form;
				var layer = layui.layer;
				var tree = layui.tree;
				var $ = layui.$;

				var index = parent.layer.getFrameIndex(window.name);

				// 提交事件
				form.on('submit(demo1)', function(data) {
					var field = data.field; // 获取表单字段值
					var checkData = tree.getChecked('demo-id-1');
					var nodeIds = getCheckedId(checkData);
					field.auth = nodeIds
					// 此处可执行 Ajax 等操作
					$.ajax({
						url: './',
						data: field,
						type: 'POST',
						dataType: "JSON",
						error: function(error) {
							layer.msg(error.msg);
						},
						success: function(res) {
							layer.msg('提交成功', {
								icon: 6,
								time: 1000, // 提示音乐播放的时间，默认3秒
							}, function() {
								// 关闭之后的回调
								// window.location.href = "/rolelist";
								// 关闭当前子页面
								parent.layer.close(index);
								// 调用父页面的方法来刷新表格
								parent.refreshTable();
							});
						}
					});
					// …
					return false; // 阻止默认 form 跳转
				});

				//获取所有选中的节点id
				function getCheckedId(data) {
					var id = "";
					$.each(data, function(index, item) {
						if (id != "") {
							id = id + "$" + item.id;
						} else {
							id = item.id;
						}
						//item 没有children属性
						if (item.children != null) {
							var i = getCheckedId(item.children);
							if (i != "") {
								id = id + "$" + i;
							}
						}
					});
					return id;
				}

				// 关闭当前子页面
				$('#closeIframe').click(function() {
					parent.layer.close(index);
				});
			});
		</script>
	</body>
</html>